﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data.EntityClient;

namespace ConsoleApplication
{
    class Program
    {
        static void Main(string[] args)
        {

            string providerName = "System.Data.SqlClient";
            string serverName = "ARCGIS";
            string databaseName = "HnMap";

            // Initialize the connection string builder for the
            // underlying provider.
            SqlConnectionStringBuilder sqlBuilder =
                new SqlConnectionStringBuilder();

            // Set the properties for the data source.
            sqlBuilder.DataSource = serverName;
            sqlBuilder.InitialCatalog = databaseName;
            sqlBuilder.IntegratedSecurity = false;
            sqlBuilder.UserID = "sa";
            sqlBuilder.Password = "sa";

            // Build the SqlConnection connection string.
            string providerString = sqlBuilder.ToString();

            // Initialize the EntityConnectionStringBuilder.
            EntityConnectionStringBuilder entityBuilder =
                new EntityConnectionStringBuilder();

            //Set the provider name.
            entityBuilder.Provider = providerName;

            // Set the provider-specific connection string.
            entityBuilder.ProviderConnectionString = providerString;

            entityBuilder.Provider = providerName;

            // Set the Metadata location.
            entityBuilder.Metadata = "res://*/GISModel.csdl|res://*/GISModel.ssdl|res://*/GISModel.msl";
                //"res://*"; //或从.config文件中copy
            //@"res://*/NBModel.csdl|
            //res://*/NBModel.ssdl|
            //res://*/NBModel.msl";
            string str = entityBuilder.ToString();

            using (GISEntity.HnMapEntities database = new GISEntity.HnMapEntities(str))
            {
                var query = from gdp in database.GDPs
                            select gdp;
                Console.WriteLine(query.Count());
                foreach (var item in query.ToList())
                {
                    Console.WriteLine(item.CITYNAME);
                }
            }
            //using (NORTHWNDEntities nwt = new NORTHWNDEntities(entityBuilder.ToString()))
            //{
            //    var query = from cat in nwt.Categories
            //                select cat;
            //    this.GridView1.DataSource = query;
            //    this.GridView1.DataBind();

            //}
        }
    }
}
